#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src

# Test that the msgmerge output is stable under an 'msgcat' invocation.
# Also test what happens with the 'no-wrap' flag during msgmerge.

cat <<\EOF > mm-test27.po
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "This is a long paragraph that gets wrapped into several lines because it is so long."
msgstr "Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist."

#, no-wrap
msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr "Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist."

msgid "This is another long paragraph that gets wrapped into several lines because it is so long."
msgstr "Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist."

#, no-wrap
msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr "Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist."
EOF

cat <<\EOF > mm-test27-1.pot
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "This is a long paragraph that gets wrapped into several lines because it is so long."
msgstr ""

#, no-wrap
msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr ""
EOF

: ${MSGMERGE=msgmerge}
${MSGMERGE} -q -o mm-test27.tmp.po mm-test27.po mm-test27-1.pot || Exit 1
LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27.new.po || Exit 1

: ${MSGCAT=msgcat}
${MSGCAT} mm-test27.new.po > mm-test27.tmp.po || Exit 1
LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27.cat.po || Exit 1

: ${DIFF=diff}
${DIFF} mm-test27.new.po mm-test27.cat.po || Exit 1

cat <<\EOF > mm-test27-1.ok
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid ""
"This is a long paragraph that gets wrapped into several lines because it is "
"so long."
msgstr ""
"Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil "
"er so lang ist."

#, no-wrap
msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr "Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist."

#~ msgid ""
#~ "This is another long paragraph that gets wrapped into several lines "
#~ "because it is so long."
#~ msgstr ""
#~ "Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen "
#~ "wird, weil er so lang ist."

#, no-wrap
#~ msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
#~ msgstr "Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist."
EOF

: ${DIFF=diff}
${DIFF} mm-test27-1.ok mm-test27.new.po || Exit 1

# Now test what happens with the 'no-wrap' flag when merging with a POT file
# where the 'no-wrap' flag is set.

cat <<\EOF > mm-test27-2.pot
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#, no-wrap
msgid "This is a long paragraph that gets wrapped into several lines because it is so long."
msgstr ""

#, no-wrap
msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr ""

#, no-wrap
msgid "This is another long paragraph that gets wrapped into several lines because it is so long."
msgstr ""

#, no-wrap
msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr ""
EOF

: ${MSGMERGE=msgmerge}
${MSGMERGE} -q -o mm-test27.tmp.po mm-test27.new.po mm-test27-2.pot || Exit 1
LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27-2.po || Exit 1

cat <<\EOF > mm-test27-2.ok
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#, no-wrap
msgid "This is a long paragraph that gets wrapped into several lines because it is so long."
msgstr "Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist."

#, no-wrap
msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr "Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist."

#, no-wrap
msgid "This is another long paragraph that gets wrapped into several lines because it is so long."
msgstr "Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist."

#, no-wrap
msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr "Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist."
EOF

: ${DIFF=diff}
${DIFF} mm-test27-2.ok mm-test27-2.po || Exit 1

# Now test what happens with the 'no-wrap' flag when merging with a POT file
# where the 'no-wrap' flag is absent.

cat <<\EOF > mm-test27-3.pot
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "This is a long paragraph that gets wrapped into several lines because it is so long."
msgstr ""

msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr ""

msgid "This is another long paragraph that gets wrapped into several lines because it is so long."
msgstr ""

msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'."
msgstr ""
EOF

: ${MSGMERGE=msgmerge}
${MSGMERGE} -q -o mm-test27.tmp.po mm-test27.new.po mm-test27-3.pot || Exit 1
LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27-3.po || Exit 1

cat <<\EOF > mm-test27-3.ok
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid ""
"This is a long paragraph that gets wrapped into several lines because it is "
"so long."
msgstr ""
"Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil "
"er so lang ist."

msgid ""
"This is a long paragraph that does not get wrapped into several lines "
"because it is marked as 'no-wrap'."
msgstr ""
"Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, "
"weil er als 'no-wrap' markiert ist."

msgid ""
"This is another long paragraph that gets wrapped into several lines because "
"it is so long."
msgstr ""
"Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen "
"wird, weil er so lang ist."

msgid ""
"This is another long paragraph that does not get wrapped into several lines "
"because it is marked as 'no-wrap'."
msgstr ""
"Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen "
"umgebrochen wird, weil er als 'no-wrap' markiert ist."
EOF

: ${DIFF=diff}
${DIFF} mm-test27-3.ok mm-test27-3.po || Exit 1

Exit 0
